package com.itheima.service.impl;

import com.itheima.domain.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class UserServiceImpl implements UserService {

    private SqlSession sqlSession = null;
    @Override
    public User findByNameAndPwd(User user) {
        try{
            SqlSession sqlSession = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("SqlMapConfig.xml")).openSession();
            UserMapper mapper = sqlSession.getMapper(UserMapper.class);
            User _user = mapper.findByNameAndPwd(user);
            return _user;
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(sqlSession!=null)
            {
                sqlSession.close();
            }
        }
        return null;
    }
}
